# -*- coding: utf-8 -*-
import numpy as np
from skimage import io
import cv2
import matplotlib.pyplot as plt

im_color = io.imread('data/retangle.png')
#im_gray = cv2.cvtColor(im_color, cv2.COLOR_RGB2GRAY)
im_gray = im_color
im_fft = np.fft.fft2(im_gray)
im_fft = np.fft.fftshift(im_fft)

im_fft_abs = np.abs(im_fft)
im_fft_abs_log = np.log10(im_fft_abs + 1)

print np.max(im_fft_abs_log)
print np.min(im_fft_abs_log)
fig = plt.figure()
plt.imshow(im_fft_abs_log)
fig.savefig('data/img_fft_abs_log_retangle.png')

im_ifft = np.fft.ifft2(im_fft)
im_ifft_real = im_ifft.real
im_ifft_real = np.clip(im_ifft_real, 0, 255)
im_fft_real_uint = np.asarray(im_ifft_real, dtype=np.uint8)
fig = plt.figure()
plt.subplot(1, 3, 1)
io.imshow(im_color)
plt.subplot(1, 3, 2)
io.imshow(im_gray)
plt.subplot(1, 3, 3)
io.imshow(np.reshape(im_fft_real_uint, (289, 174)))
io.show()
fig.savefig('data/retangle_plot.png')
